package com.scuec.groupfive.service.impl;

import com.scuec.groupfive.entity.UserInfo;
import com.scuec.groupfive.mapper.UserMapper;
import com.scuec.groupfive.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public List<UserInfo> getUserList() {
        return userMapper.getUserList();
    }

    @Override
    public UserInfo getUserById(Integer userId) {
        return userMapper.getUserById(userId);
    }

    @Override
    public int updateUserStatus(Integer userId, Integer status) {
        if (status != 0 && status != 1) {
            throw new IllegalArgumentException("状态值必须是0或1");
        }
        return userMapper.updateUserStatus(userId, status);
    }

    @Override
    public int updateUserInfo(UserInfo userInfo) {
        if (userInfo.getRole() != null &&
                !userInfo.getRole().equals("admin") &&
                !userInfo.getRole().equals("student")) {
            throw new IllegalArgumentException("角色必须是admin或student");
        }
        return userMapper.updateUserInfo(userInfo);
    }
}